package com.example.class_manage.Controller;

import com.example.class_manage.Entity.Howework_pic;
import com.example.class_manage.Mapper.HomeWork_text_mapper;
import com.example.class_manage.Util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.example.class_manage.Entity.Homework_text;
import java.io.IOException;
import java.util.List;


@RestController
@Slf4j
@RequestMapping("/Homework_text")
@Api(tags = "文字作业接口")
public class HomeWork_text_Controller {
    @Autowired
    HomeWork_text_mapper homeWork_text_mapper;


    @ApiOperation("查询此次所有作业通过作业号")
    @GetMapping("/Get_Class_HomeWork_text")
    public JsonData Get_Class_HomeWork_text(
            @ApiParam(value = "作业id", required = true) @RequestParam String id
    ) {
        List<Homework_text> homework_texts = homeWork_text_mapper.Find_Homework_byid(id);
        if (homework_texts.size() == 0) {
            return JsonData.buildError("无此次作业,请检查作业id");
        } else
            return JsonData.buildSuccess(homework_texts, "查询此次作业成功");
    }

    @ApiOperation("查询所有写完的文字作业")
    @GetMapping("/FindAll_HomeWork_text")
    public JsonData GetAll_HomeWork() {
        List<Homework_text> Result = homeWork_text_mapper.Test_findAlltext();
        return JsonData.buildSuccess(Result, "查询成功");
    }

    //批阅方式
    @ApiOperation("查找助教需要批阅的作业")
    @GetMapping("/Homework_text_bymark_assistant")
    public JsonData Homework_text_bymark_assistant(@ApiParam(value = "作业id",required = true)@RequestParam String id) {

        List<Homework_text> homework_text_assiatant = homeWork_text_mapper.Review_All_text_bymark_flag_assiatant(id);
        return homework_text_assiatant != null ? JsonData.buildSuccess(homework_text_assiatant, "作业查询成功") : JsonData.buildError("查询失败");
    }
    @ApiOperation("查找老师需要批阅的作业")
    @GetMapping("/Homework_text_bymark_teacher")
    public JsonData Homework_text_bymark_teacher(@ApiParam("作业号") @RequestParam String id) {

        List<Homework_text> homework_text_teacher = homeWork_text_mapper.Review_All_text_bymark_flag_teacher(id);
        System.out.println(homework_text_teacher.size());
        return homework_text_teacher != null ? JsonData.buildSuccess(homework_text_teacher, "作业查询成功") : JsonData.buildError("查询失败");

    }

    @ApiOperation("设置批阅方式")
    @GetMapping("/Up_text_mark")
    public JsonData Up_text_mark(
            @ApiParam(value = "批阅标记", required = true) @RequestParam String mark_flag,
            @ApiParam(value = "作业Id", required = true) @RequestParam String id
    ) {
        Integer statu = 0;
        statu = homeWork_text_mapper.UpHomework_text_mark(mark_flag, id);
        return statu != 0 ? JsonData.buildSuccess("标记成功") : JsonData.buildError("标记失败");
    }

    @ApiOperation("查找学生需要批阅的作业")
    @GetMapping("/Homework_text_bymark_student")
    public JsonData Homework_text_bymark_student(
            @ApiParam(value = "批阅标记", required = true) @RequestParam String mark_flag) {
        List<Homework_text> homework_text_student = homeWork_text_mapper.Review_All_text_bymark_flag(mark_flag);
        return homework_text_student != null ? JsonData.buildSuccess(homework_text_student, "作业查询成功") : JsonData.buildError("查询失败");
    }



}
